package main

import (
	"context"
	"fmt"
	"github.com/olivere/elastic"
	"log"
	"os"
	"github.com/astaxie/beego"
)

var client *elastic.Client;
func init()  {
	var err error
	errorlog := log.New(os.Stdout, "APP", log.LstdFlags)
	beego.LoadAppConfig("ini","../conf/app.conf")
	eshost := beego.AppConfig.String("es_host")
	elastic.SetHealthcheck(false)
	elastic.SetSniff(false)
	client,err = elastic.NewClient(elastic.SetErrorLog(errorlog), elastic.SetURL(eshost))
	if err!=nil {
		panic(err)

	}
}

func main()  {
	searchResult,_ := client.Search("searchlist").Type("post").Do(context.Background());
	for _,botInfo := range searchResult.Hits.Hits{
		fmt.Printf("%s\n",*botInfo.Source);
	}
}